<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <link href="/layui/css/layui.css" rel="stylesheet">
    <title>用户登录</title>
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <script src="/layui/layui.js"></script>
    <meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=yes">
    <style type="text/css">
        .container{
            width: 420px;
            height: 320px;
            min-height: 320px;
            max-height: 320px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            padding: 20px;
            z-index: 130;
            border-radius: 8px;
            background-color: #fff;
            box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
            font-size: 16px;
        }
        .close{
            background-color: white;
            border: none;
            font-size: 18px;
            margin-left: 410px;
            margin-top: -10px;
        }

        .layui-input{
            border-radius: 5px;
            width: 300px;
            height: 40px;
            font-size: 15px;
        }
        .layui-form-item{
            margin-left: -20px;
        }
        #logoid{
            margin-top: -16px;
            padding-left:150px;
            padding-bottom: 15px;
        }
        .layui-btn{
            margin-left: -50px;
            border-radius: 5px;
            width: 350px;
            height: 40px;
            font-size: 15px;
        }
        .verity{
            width: 120px;
        }
        .font-set{
            font-size: 13px;
            text-decoration: none;
            margin-left: 120px;
        }
        a:hover{
            text-decoration: underline;
        }
        body
        {
           /*这个没错 不知道为啥解析不了*/
            background-image:url('/img/background.png');
            background-size: 100% 100%;
            background-repeat:no-repeat;
            background-attachment: fixed;
        }
        @media screen and (max-width: 768px) {
            body{
                background-image: url('/img/loginBackgroundforCellPhone.jpg');
                background-size: 100% 100%;
                background-repeat:no-repeat;
                background-attachment: fixed;
            }


        }
        @media screen and (max-width: 450px){
            .layui-inline div img{
                margin-left: 7rem;
            }
            label{
                font-size: 1.3rem;
            }
            .layui-input{
                font-size: 1.3rem;
            }
        }
    </style>
</head>
<body>
<div class="container">
<form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="open" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密 &nbsp;&nbsp;码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="open" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                    <input type="text" name="code"class="layui-input"placeholder="请输入验证码">
                </div>
            </div>
            <div class="layui-inline">
                    <div> <img src="/code/img" style="height:40px;cursor:pointer;"
                               onclick="this.src='/code/img?'+ new Date().getTime()"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
            </div>
        </div>
    <div>
        <span id="returnsign" style="color:red"></span>
    </div>
</form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var $=layui.$
        $("form").submit(function(event) {
            event.preventDefault(); // 阻止表单默认提交行为

            var username = $("input[name='username']").val();
            var password = $("input[name='password']").val();
            var code = $("input[name='code']").val();
            $.ajax({
                type: "POST",
                url: "/tologin",
                data: {
                    username: username,
                    password: password,
                    code:code
                },
                success: function(data) {
                    console.log(data)
                    window.location.href = "/main";
                },
                error: function(xhr, status, error) {
                    var errorMessage = xhr.responseText;
                    // 处理登录失败的响应
                    $("#returnsign").text(errorMessage)
                }
            });
        });
    });
    if(top.location != location) {
        top.location.href = location.href;
    }
</script>
</body>
</html>